//
//  AuthUploadTableViewCell.m
//  LPTClient
//
//  Created by apple on 2018/12/10.
//  Copyright © 2018 zhaodd. All rights reserved.
//

#import "AuthUploadTableViewCell.h"

@interface AuthUploadTableViewCell()

@property (nonatomic, weak) IBOutlet UILabel *titleLab;
@property (nonatomic, weak) IBOutlet UILabel *descLab;
@property (nonatomic, weak) IBOutlet UIButton *button;

@end

@implementation AuthUploadTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self reloadImageUrl:@""];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)refreshWithDict:(NSDictionary *)dict
{
    NSString *title = dict[@"name"];
    NSString *placeholder = dict[@"desc"];
    NSString *key = dict[@"key"];
    
    self.titleLab.text = title;
    self.descLab.text = placeholder;
    
    objc_setAssociatedObject(self.button, @"button.key", key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self reloadImageUrl:[dict valueForKey:@"imageInfo"]];
}

- (void)reloadImageUrl:(ImageInfo *)imgInfo
{
    if (imgInfo) {
        if ([imgInfo isMemberOfClass:[ImageInfo class]]) {
            NSString *urlStr = IMG_URL(imgInfo.url);
            NSURL *url_ = [NSURL URLWithString:urlStr];
            [self.button setImageWithURL:url_ forState:UIControlStateNormal placeholder:[UIImage imageNamed:@"home_banner_loading"]];
        }else {
            [self.button setImage:[UIImage imageNamed:@"aut_bg_upload"] forState:UIControlStateNormal];
        }
    }else {
        [self.button setImage:[UIImage imageNamed:@"aut_bg_upload"] forState:UIControlStateNormal];
    }
    
}
@end
